<template>
  <div>
    <el-card header="今天吃几个菜：？">
      <el-input-number v-model="eatValue"></el-input-number>
    </el-card>
    <el-card header="今天吃">
      <template #header>
        <el-button type="primary" @click="confirm">今天吃什么</el-button>
      </template>
      <div
        v-for="(item ,index) in show"
        :key="'show'+index"
        class="eatItem"
      >
        <div>菜名：{{item.name}}</div>
        <div>材料：{{item.material}}</div>
      </div>
    </el-card>
    <el-card header="菜单数据">
      <el-tag
        v-for="(item ,index) in data"
        :key="'data'+index"
      >{{item.name}}</el-tag>
    </el-card>
  </div>
</template>

<script>
import data from "./data.js";
import Utils from "../../utils/Utils.js";

export default {
  name: 'ToDayWhatEat',
  data() {
    return {
      eatValue: 2,
      show: [],
      data,
    }
  },
  methods: {
    confirm() {
      if(this.data.length <= this.eatValue) {
        this.show = this.data
        return
      }
      this.show = Utils.deepClone(this.data)
        .sort(() => Math.random() - 0.5)
        .slice(0, this.eatValue);
    }
  }
}
</script>

<style lang="less" scoped>
.eatItem {
  margin-top: 20px;
  &:first-of-type{
    margin-top: 0px;
  }
}
</style>
